/* NullValue.cs -- 
   Copyright (C) 2008 Pacific Biosciences, Inc. */


using System;
using SexpSharp;

namespace SexpSharp.RPC
{
	/// <summary>
	/// A null value.
	/// </summary>
	public sealed class NullValue : IValue
	{
		private static NullValue instance = new NullValue();

		private NullValue()
		{
		}

		public NullValue(Expression expr)
		{
			List l = expr as List;
			if (l == null)
				throw new ArgumentException("must be a list", "expr");
			if (l.Count != 1 || !(l[0] is Atom))
				throw new ArgumentException("list must have exactly two atoms");
			if (l[0].ToString() != "nil")
				throw new ArgumentException("first item of list must be 'nil'");
		}

		public static NullValue Instance
		{
			get
			{
				return instance;
			}
		}

		public Expression ToExpression()
		{
			List l = new List();
			l.Add(new Atom("nil"));
			return l;
		}

		public override string ToString()
		{
			return "null";
		}

		public bool Equals(IValue val)
		{
			return val is NullValue;
		}

		public override bool Equals(object o)
		{
			return o is NullValue;
		}

		public override int GetHashCode()
		{
			return 0;
		}
	}
}
